#ifndef ECO_PRODUCTS_PARSER_H
#define ECO_PRODUCTS_PARSER_H

#include "Product.h"
#include "Proveider.h"
#include "ProductsModel.h"

#include <vector>
#include <QTextStream>
#include <QFile>

namespace ecocity
{

class ProductsParser
{
    // Enum from ProductModel should have same order
    // use same enum ?? Bad idea. Assert that order is the same ...
    enum COLUMN
    {
        PRODUCT_ID                   = 0,
        PRODUCT_NAME                 = 1,
        PRODUCT_DESCRIPTION          = 2,
        PRODUCT_PROVIDER             = 3,
        PRODUCT_TAX_RATE             = 4,
        PRODUCT_PRICE_COOPE          = 5,
        PRODUCT_PRICE_SHOP           = 6,
        PRODUCT_PRICE_END_CUSTOMER   = 7,
        PRODUCT_COST_ECOCITY         = 8,
        PRODUCT_PRICE_TYPE           = 9,
        PRODUCT_PROFIT_RATE          = 10
    };

public:

    static bool parse( const QString& file_products_csv,
                       std::vector< Product >& products,
                       std::vector< Proveider >& proveiders );

    static std::vector< int > separators_in_line( const QString& line,
                                                  const char separator = ';' );

    static Product to_product( const QString& line, const char separator = ';' );
    static Proveider to_proveider( const QString& line, const char separator = ';' );

private:

    static void parse_line( const QString& line,
                            std::vector< Product >& products,
                            const char separator = ';' );

    static bool parse_file( QFile& stream,
                            std::vector< Product >& products,
                            std::vector< Proveider >& proveiders,
                            const char separator = ';' );
};

}      // namespace liga

#endif // ECO_PRODUCTS_PARSER_H
